﻿using System;
using ExtraClub.Domain;
using ExtraClub.Domain.Entities;
using SubSonic;
using System.Collections.Generic;
using ExtraClub.Domain.Framework;
using System.Reflection;

namespace ExtraClub.Web.Controls.club_grid {
    public partial class module : BaseModule {
        protected List<VwClubProfile> list = null;

        public List<string> ColumnCollection { get; set; }

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            Query q = VwClubProfile.Query();

            string key = "club_grid_filter";


            Dictionary<string, object> data = Items.ContainsKey("data") ? (Dictionary<string, object>)Items["data"] :  (Dictionary<string, object>)Session[key];
            if (data != null) {
                SiteContext.Current.SetLanguage(data["lang"].ToString());

                q.AddWhere(VwClubProfile.Columns.UserName, Comparison.Like, "%" + data[VwClubProfile.Columns.UserName.ToLower()].ToString().Trim().ToLower() + "%");
                q.AddWhere(VwClubProfile.Columns.Email, Comparison.Like, "%" + data[VwClubProfile.Columns.Email.ToLower()].ToString().Trim().ToLower() + "%");
                q.AddWhere(VwClubProfile.Columns.Password, Comparison.Like, "%" + data[VwClubProfile.Columns.Password.ToLower()].ToString().Trim().ToLower() + "%");
                q.AddWhere(VwClubProfile.Columns.Name, Comparison.Like, "%" + data[VwClubProfile.Columns.Name.ToLower()].ToString().Trim().ToLower() + "%");
                q.AddWhere(VwClubProfile.Columns.FirstName, Comparison.Like, "%" + data[VwClubProfile.Columns.FirstName.ToLower()].ToString().Trim().ToLower() + "%");

                Session[key] = data;
            }

            list = VwClubProfile.LoadByQuery(q).GetList();

            if (SiteContext.Current.Club != null) {
                list.RemoveAll(delegate(VwClubProfile item) {
                    return SiteContext.Current.Club.Id == item.Id;
                });
            }

            AddMailForm.LoadForm(RequestedForm);
        }
    }
}